package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.PageResult;
import com.xrit.sunnyday.entity.QueryPageBean;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.CheckItem;
import com.xrit.sunnyday.pojo.Permission;
import com.xrit.sunnyday.service.PermissionService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Reference
    private PermissionService permissionService;

    /**
     * 分页条件查询
     */
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        // 调用业务查询
        PageResult pageResult = permissionService.findPage(queryPageBean);
        return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,pageResult);
    }

    //新增权限
    @PostMapping("/add")
    public Result add(@RequestBody Permission permission){
        permissionService.add(permission);
        return new Result(true,MessageConstant.ADD_PERMISSION_SUCCESS);
    }

    /**
     * 删除权限
     */
    @DeleteMapping("/deleteById")
    public Result deleteById(int id){
        //调用业务服务删除
        permissionService.deleteById(id);
        return new Result(true,MessageConstant.DELETE_PERMISSION_SUCCESS);
    }

    /**
     * 通过id查询
     */
    @GetMapping("/findById")
    public Result findById(int id){
        Permission permission = permissionService.findById(id);
        return new Result(true, MessageConstant.QUERY_PERMISSION_SUCCESS,permission);
    }

    /**
     * 修改检查项
     */
    @PostMapping("/update")
    public Result update(@RequestBody Permission permission){
        // 调用业务服务
        permissionService.update(permission);
        // 响应结果给前端
        return new Result(true, MessageConstant.EDIT_PERMISSION_SUCCESS);
    }
}
